package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.dto.BedDto;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/alert-rule")
@Api(tags = "告警规则管理")
public class AlertRuleController extends BaseController{

    @Autowired
    private AlertRuleService alertRuleService;

    @PostMapping("/create")
    @ApiOperation(value = "新增告警规则")
    public ResponseResult create(@RequestBody AlertRuleDto alertRuleDto){
        alertRuleService.create(alertRuleDto);
        return ResponseResult.success();
    }

    @GetMapping("/get-page")
    @ApiOperation(value = "分页查询报警规则")
    public ResponseResult<PageResponse> getPage(Integer pageNum, Integer pageSize, String alertRuleName, String functionName, String productKey){
       PageResponse<AlertRuleVo> response =  alertRuleService.getPage(pageNum, pageSize, alertRuleName, functionName, productKey);
        return success(response);
    }

    @PutMapping("/update/{id}")
    @ApiOperation(value = "更新告警规则", notes = "接收一个id参数和一个AlertRuleDto对象作为请求参数，返回void")
    public ResponseResult updateAlertRule(@PathVariable Long id, @RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.updateAlertRule(id, alertRuleDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除告警规则", notes = "接收一个id参数作为请求参数，返回void")
    public ResponseResult deleteAlertRule(@PathVariable Long id) {
        alertRuleService.deleteAlertRule(id);
        return ResponseResult.success();
    }
}
